/*
** 101jacobi.c for  in /home/jousse_f//afs/rendu/math/101jacobi
** 
** Made by florian jousseau
** Login   <jousse_f@epitech.net>
** 
** Started on  Tue Nov 23 12:12:47 2010 florian jousseau
** Last update Tue Nov 23 14:31:45 2010 florian jousseau
*/

#include <stdlib.h>
#define DIM	(my_getnbr(av[1]))

int	aff_dimension(int ac, char **av)
{
  my_putstr("Dimension\n");
  my_putstr(av[1]);
  my_putchar('\n');
  return (0);
}

int	**malloc_matrix(int ac, char **av)
{
  int	**tab;
  int	i;
  int	j;

  i = 0;
  j = 0;
  tab = malloc(sizeof(*tab) * DIM);
  while (i < DIM)
    {
      j = 0;
      tab[i] = malloc(sizeof(**tab) * DIM);
      while (j < DIM)
   	{
   	  tab[i][j] = 0;
   	  j++;
   	}
      i++;
    }
  return (tab);
}

int	**creat_matrix(int **tab, char **av)
{
  int	i;
  int	j;

  i = 0;
  j = 0;
  tab[i][j] = 2;
  while (i < DIM)
    {
      tab[i][j - 1] = -1;
      tab[i][j] = 2;
      tab[i][j + 1] = -1;
      j++;
      i++;
    }
  return (tab);
}

int	**aff_matrix(int **tab, char **av)
{
  int	i;
  int	j;

  i = 0;
  j = 0;
  my_putstr("Matrice A");
  my_putchar('\n');
  while (i < DIM)
    {
       j = 0;
      while (j < DIM)
	{
	  my_put_nbr(tab[i][j]);
	  my_putchar(' ');
	  j++;
	}
      my_putchar('\n');
      i++;
    }
}

int	aff_vecteur(int	**tab, char **av)
{
  int	i;
  int	j;
  int	line;

  i = 0;
  j = 0;
  line = 0;
  my_putstr("vecteur b\n");
  while (i < DIM)
    {
      j = 0;
      line = 0;
      while (j < DIM)
	{
	  line += tab[i][j];
	  j++;
	}
      i++;
      my_put_nbr(line);
      my_putchar('\n');
    }
}

int	jacobi(int ac, char **av)
{
  int	**tab;

  aff_dimension(ac, av);
  tab = malloc_matrix(ac, av);
  tab = creat_matrix(tab, av);
  aff_matrix(tab, av);
  aff_vecteur(tab, av);
  return (0);
}

int	main(int ac, char **av)
{
  jacobi(ac, av);
  return (0);
}
